package com.zyd.blog.personal.service.impl;

import	java.util.HashMap;

import com.zyd.blog.persistence.mapper.ProtocolMapper;
import com.zyd.blog.personal.po.ProtocolPo;
import com.zyd.blog.personal.service.ProtocolService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 协议处理业务逻辑层
 * @author mfy
 */
@Service
public class ProtocolServiceImpl implements ProtocolService {
    @Resource
    private ProtocolMapper protocolMapper;

    @Override
    public Map<String,Object> queryProtocolByCondition(String type){
        Map<String,Object> protocolCondition = new HashMap<>(16);
        protocolCondition.put("type",type);
        List<Map<String,Object>> protocols = protocolMapper.queryProtocolByCondition(protocolCondition);
        if(protocols == null || protocols.size() == 0){
            return null;
        }
        return protocols.get(0);
    }

    @Override
    public Boolean addProtocolInfoByJson(){
//        Map<String,String> condition = new HashMap<>(16);
//
//        Map<String,Object> content = new HashMap<>(16);
//
//        content.put("title","标题");
//        List<Map<String,String>> body = new ArrayList<> ();
//        Map<String,String> paragraphVo1 = new HashMap<> (16);
//        paragraphVo1.put("subTitle","第一段");
//        paragraphVo1.put("content","第一段内容");
//
//        Map<String,String> paragraphVo2 = new HashMap<> (16);
//        paragraphVo2.put("subTitle","第二段");
//        paragraphVo2.put("content","第二段内容");
//
//        body.add(paragraphVo1);
//        body.add(paragraphVo2);
//
//        content.put("body",body);
//
//        System.out.println(content);
//        String contentStr = JSON.toJSONString(content);
//        System.out.println(contentStr);
//
//        condition.put("type","MerchantCooperation");
//        condition.put("content",contentStr);
//        condition.put("updateTime",(new Date()).getTime() + "");
//        condition.put("addTime",(new Date()).getTime() + "");
//
//        if(protocolMapper.addProtocolInfo(condition) > 0){
//            System.out.println("添加成功");
//            return true;
//        }else{
//            System.out.println("添加失败");
//            return false;
//        }
        return false;
    }

    @Override
    public Boolean updateProtocolInfo(){
        return true;
    }

}
